package org.cheetah.core.action.spi;

import javax.xml.bind.annotation.XmlAccessOrder;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorOrder;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

import org.cheetah.core.Service;
import org.cheetah.core.endpoint.Endpoints;
import org.cheetah.core.impl.DefaultServiceInvoker;

@XmlRootElement(name = "from")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlAccessorOrder(XmlAccessOrder.ALPHABETICAL)
public class FromDefinition {

	@XmlAttribute(name = "uri", required = true)
	private String uri;

	public FromDefinition uri(String uri) {
		this.uri = uri;
		return this;
	}

	public void start(Service service) throws Exception {
		Endpoints.createConsumer(uri).asyncReceive(
				new DefaultServiceInvoker(service));
	}
}
